package book.serviceImpl;

import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import book.dao.bookDAO;
import book.dto.book;
import book.service.bookService;
import book.util.Page;
import book.util.PageUtil;
import book.util.Result;

@Transactional
public class bookServiceImpl implements bookService {

	private bookDAO bookDAO;

	public bookDAO getBookDAO() {
		return bookDAO;
	}

	public void setBookDAO(bookDAO bookDAO) {
		this.bookDAO = bookDAO;
	}

	public Integer count() {
		return bookDAO.count();
	}

	public void update(book book) {
		bookDAO.update(book);
	}

	public void add(book book) {
		bookDAO.add(book);
	}

	public void delete(Integer bid) {
		bookDAO.delete(bid);
	}

	public Result query(Page page) {
		int totalRecords = bookDAO.count();
		Page page1 = PageUtil.createPage(page, totalRecords);
		List books = bookDAO.query(page1);
		return new Result(page1, books);
	}

	public Result query(Page page, String key) {
		int totalRecords = bookDAO.count(key);
		Page page1 = PageUtil.createPage(page, totalRecords);
		List books = bookDAO.query(page1, key);
		return new Result(page1, books);
	}
}
